package api

import (
	"api-gateway/basic/inits"
	__ "api-gateway/basic/user_proto"
	"api-gateway/handler/request"
	"api-gateway/handler/response"
	"context"
	"github.com/gin-gonic/gin"
)

// BadgeRulesAdd
// @Summary      勋章规则添加
// @Description  勋章规则添加
// @Tags         勋章模块
// @Accept       json
// @Produce      json
// @Param        HotSearch  body      request.BadgeRulesAdd  true  "首页参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Router       /medal/badgeRulesAdd [post]
func BadgeRulesAdd(c *gin.Context) {
	var req request.BadgeRulesAdd
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}

	add, err := inits.UserClient.BadgeRulesAdd(context.Background(), &__.BadgeRulesAddReq{
		Name:      req.Name,
		Desc:      req.Desc,
		Condition: req.Condition,
	})
	if err != nil {
		response.Error(c, 400, err.Error(), nil)
		return
	}
	response.Success(c, "勋章规则添加成功", add)

}

// UserBadgesAdd
// @Summary      用户勋章添加
// @Description  用户勋章添加
// @Tags         勋章模块
// @Accept       json
// @Produce      json
// @Param        HotSearch  body      request.UserBadgesAdd  true  "首页参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Router       /medal/userBadgesAdd [post]
func UserBadgesAdd(c *gin.Context) {
	var req request.UserBadgesAdd
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}

	add, err := inits.UserClient.UserBadgesAdd(context.Background(), &__.UserBadgesAddReq{
		UserId:  req.UserId,
		RulesId: req.RulesId,
	})

	if err != nil {
		response.Error(c, 400, err.Error(), nil)
		return
	}
	response.Success(c, "勋章添加成功", add)
}

// UserBadgesFind
// @Summary      用户勋章展示
// @Description  用户勋章展示
// @Tags         勋章模块
// @Accept       json
// @Produce      json
// @Param        HotSearch  query      request.UserBadgesFind  true  "首页参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Security TokenAuth
// @Router       /medal/userBadgesFind [get]
func UserBadgesFind(c *gin.Context) {
	userId := c.GetUint("userId")
	var req request.UserBadgesFind
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	find, err := inits.UserClient.UserBadgesFind(context.Background(), &__.UserBadgesFindReq{
		UserId: uint64(userId),
	})
	if err != nil {
		response.Error(c, 400, err.Error(), nil)
		return
	}
	response.Success(c, "勋章展示成功", find)
}

// BadgeRulesDetail
// @Summary      勋章规则详情
// @Description  勋章规则详情
// @Tags         勋章模块
// @Accept       json
// @Produce      json
// @Param        HotSearch  query      request.BadgeRulesDetail  true  "首页参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Security TokenAuth
// @Router       /medal/badgeRulesDetail [get]
func BadgeRulesDetail(c *gin.Context) {
	userId := c.GetUint("userId")
	var req request.BadgeRulesDetail
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	detail, err := inits.UserClient.BadgeRulesDetail(context.Background(), &__.BadgeRulesDetailReq{
		UserId: uint64(userId),
		Id:     req.Id,
	})
	if err != nil {
		response.Error(c, 400, err.Error(), nil)
		return
	}
	response.Success(c, "勋章规则详情展示成功", detail)
}
